home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 3.0 KB | 127 lines | [TEXT/CWIE] |
- // ConstArrayOf.cp
-
- #ifndef ConstArrayOf_h
- #include "ConstArrayOf.h"
- #endif
- #ifndef MinMax_h
- #include "MinMax.h"
- #endif
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::Head( uint32 size ) const
- {
- Assert( !Null() );
- Assert( size <= length );
- return ConstArrayType( start, size );
- }
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::Tail( uint32 position ) const
- {
- Assert( !Null() );
- Assert( position <= length );
- return ConstArrayType( start + position, length - position );
- }
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::Middle( URange32 range ) const
- {
- Assert( !Null() );
- Assert( range.End() <= length );
- return ConstArrayType( start + range.Start(), range.Length() );
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Truncate( uint32 position )
- {
- Assert( !Null() );
- Assert( position <= length )
- length = position;
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Shorten( uint32 amount )
- {
- Assert( !Null() );
- Assert( amount <= length );
- start += amount;
- length -= amount;
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Append( ConstArrayType tail )
- {
- Assert( !Null() );
- Assert( Precedes( tail ) );
- length += tail.length;
- }
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::operator+( ConstArrayType tail ) const
- {
- ConstArrayType result( *this );
- result += tail;
- return result;
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Prepend( ConstArrayType head )
- {
- Assert( !Null() );
- Assert( Follows( head ) );
- start = head.start;
- length += head.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::operator<=( ConstArrayType r ) const
- {
- return start >= r.start && End() <= r.End();
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::operator<( ConstArrayType r ) const
- {
- return *this <= r && *this != r;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::IsHeadOf( ConstArrayType r ) const
- {
- return start == r.start && length <= r.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::IsTailOf( ConstArrayType r ) const
- {
- return End() == r.End() && length <= r.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::Touches( ConstArrayType r ) const
- {
- return End() >= r.start && start <= r.End();
- }
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::operator&( ConstArrayType r ) const
- {
- Assert( !Null() );
- Assert( !r.Null() );
- Assert( Touches( r ) );
- const Element *lastStart = Max( start, r.start );
- const Element *firstEnd = Min( End(), r.End() );
- return ConstArrayType( lastStart, firstEnd - lastStart );
- }
-
- template < class Element >
- ConstArrayOf<Element> ConstArrayOf<Element>::operator|( ConstArrayType r ) const
- {
- Assert( !Null() );
- Assert( !r.Null() );
- Assert( Touches( r ) );
- const Element *firstStart = Min( start, r.start );
- const Element *lastEnd = Max( End(), r.End() );
- return ConstArrayType( firstStart, lastEnd - firstStart );
- }
-